package com.whj.serviceorder.controller;

import com.whj.internalcommon.constant.CommonStatusEnum;
import com.whj.internalcommon.constant.HeaderParamConstants;
import com.whj.internalcommon.constant.IdentityConstant;
import com.whj.internalcommon.dto.ResponseResult;
import com.whj.internalcommon.dto.TokenResult;
import com.whj.internalcommon.request.OrderRequest;
import com.whj.internalcommon.utils.JwtUtils;
import com.whj.serviceorder.entity.OrderInfo;
import com.whj.serviceorder.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;

/**
 * @Auther: wanghaijun
 * @Date: 2023/1/28 - 01 - 28 - 14:59 
 * @Description: com.whj.serviceorder.controller
 */

@RestController
@RequestMapping("/order")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderService;

    /**
     *乘客下单 添加订单信息
     * 乘客 id 和手机号 是由 api-passenger服务解析传给前端，前端发送过来
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/add")
    public ResponseResult orderAdd(@RequestBody OrderRequest orderRequest , HttpServletRequest httpServletRequest){
//
//        // 设备唯一表示码，测试通过的案例
//        String deviceCode = httpServletRequest.getHeader(HeaderParamConstants.DEVICE_CODE);
//        orderRequest.setDeviceCode(deviceCode);

        ResponseResult responseResult = orderService.orderAdd(orderRequest);

        return responseResult;
    }

    /**
     * 司机去接乘客
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/to-pick-up-passenger")
    public ResponseResult changeStatus(@RequestBody OrderRequest orderRequest){
        return orderService.toPickUpPassenger(orderRequest);
    }

    /**
     * 司机到达接乘客的位置
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/arrived-departure")
    public ResponseResult arriveDeparture(@RequestBody OrderRequest orderRequest){
        return orderService.arriveDeparture(orderRequest);
    }

    /**
     * 司机接到乘客
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/pick-up-passenger")
    public ResponseResult pickUpPassenger(@RequestBody OrderRequest orderRequest){
        return orderService.pickUpPassenger(orderRequest);
    }

    /**
     * 乘客达到目的地,订单中止
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/passenger-getoff")
    public ResponseResult passengerGetOff(@RequestBody OrderRequest orderRequest){
        return orderService.passengerGetOff(orderRequest);
    }

    /**
     * 对订单支付完成
     *
     * @param orderRequest 订单id
     * @return
     */
    @PostMapping("/pay")
    public ResponseResult pay(@RequestBody OrderRequest orderRequest){
        return orderService.pay(orderRequest);
    }

    /**
     * 订单支付 修改订单的状态
     *
     * @param orderRequest
     * @return
     */
    @PostMapping("/push-pay-info")
    public ResponseResult pushPay(@RequestBody OrderRequest orderRequest){
        return orderService.pushPay(orderRequest);
    }

    /**
     * 订单取消
     *
     * @param orderId 取消id
     * @param identity 取消的身份表示，1 乘客，2司机
     * @return
     */
    @PostMapping("/cancel")
    public ResponseResult cancel(Long orderId,String identity){
        return orderService.cancel(orderId,identity);
    }

    /**
     * 订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/detail")
    public ResponseResult<OrderInfo> detail(Long orderId){
        return orderService.detail(orderId);
    }

    @GetMapping("/current")
    public ResponseResult current(String phone , String identity){
        return orderService.current(phone , identity);
    }
}
